use "$project_path/data/4_regdata/regdata", clear

** Building a government intervention index
egen diff_m1_chix_govint = rowmean(std_diff_m1_exp_gdp std_diff_m1_tax_revenue_wb std_diff_m1_debt_imf)
egen adiff_m1_chix_govint = rowmean(std_adiff_m1_exp_gdp std_adiff_m1_tax_revenue_wb std_adiff_m1_debt_imf)

** Appendix Figure E.7(a)1

rdrobust std_diff_m1_exp_gdp runvar
local rdd_tau : di %8.3f e(tau_cl)
local rdd_lb : di %8.3f e(ci_l_rb)
local rdd_lb = subinstr("`rdd_lb'", " ", "", .)
local rdd_ub : di %8.3f e(ci_r_rb)
local rdd_ub = subinstr("`rdd_ub'", " ", "", .)
local rdd_pval : di %8.3f e(pv_rb)
if e(pv_rb)<0.001 local rdd_pval = "<0.001"
local N = e(N)
local rd_est = "RD est.: `rdd_tau' [`rdd_lb', `rdd_ub']. p-value: `rdd_pval'. N = `N'"

rdplot std_diff_m1_exp_gdp runvar if inrange(runvar, -20, 20), p(1) nbins(10 10) graph_options(xtitle("Margin of victory of the challenger", size(large)) ylabel(-0.5(0.25)0.5, angle(0) labsize(large)) graphregion(color(white)) note("`rd_est'", tstyle(size(medlarge))) xlabel(-20(5)20, labsize(large)) ytitle("Standard deviations", size(large)) legend(off) title("Government expenditures (% of GDP)", size(large)))
graph export "$project_path/output/appendix_figures/Appendix_Figure_E7a1.pdf", as(pdf) name("Graph") replace

** Appendix Figure E.7(a)2

rdrobust std_diff_m1_tax_revenue_wb runvar
local rdd_tau : di %8.3f e(tau_cl)
local rdd_lb : di %8.3f e(ci_l_rb)
local rdd_lb = subinstr("`rdd_lb'", " ", "", .)
local rdd_ub : di %8.3f e(ci_r_rb)
local rdd_ub = subinstr("`rdd_ub'", " ", "", .)
local rdd_pval : di %8.3f e(pv_rb)
if e(pv_rb)<0.001 local rdd_pval = "<0.001"
local N = e(N)
local rd_est = "RD est.: `rdd_tau' [`rdd_lb', `rdd_ub']. p-value: `rdd_pval'. N = `N'"

rdplot std_diff_m1_tax_revenue_wb runvar if inrange(runvar, -20, 20), p(1) nbins(10 10) graph_options(xtitle("Margin of victory of the challenger", size(large)) ylabel(-0.5(0.25)0.5, angle(0) labsize(large)) graphregion(color(white)) note("`rd_est'", tstyle(size(medlarge))) xlabel(-20(5)20, labsize(large)) ytitle("Standard deviations", size(large)) legend(off) title("Tax revenue (% of GDP)", size(large)))
graph export "$project_path/output/appendix_figures/Appendix_Figure_E7a2.pdf", as(pdf) name("Graph") replace

** Appendix Figure E.7(a)3

rdrobust std_diff_m1_debt_imf runvar
local rdd_tau : di %8.3f e(tau_cl)
local rdd_lb : di %8.3f e(ci_l_rb)
local rdd_lb = subinstr("`rdd_lb'", " ", "", .)
local rdd_ub : di %8.3f e(ci_r_rb)
local rdd_ub = subinstr("`rdd_ub'", " ", "", .)
local rdd_pval : di %8.3f e(pv_rb)
if e(pv_rb)<0.001 local rdd_pval = "<0.001"
local N = e(N)
local rd_est = "RD est.: `rdd_tau' [`rdd_lb', `rdd_ub']. p-value: `rdd_pval'. N = `N'"

rdplot std_diff_m1_debt_imf runvar if inrange(runvar, -20, 20), p(1) nbins(10 10) graph_options(xtitle("Margin of victory of the challenger", size(large)) ylabel(-0.5(0.25)0.5, angle(0) labsize(large)) graphregion(color(white)) note("`rd_est'", tstyle(size(medlarge))) xlabel(-20(5)20, labsize(large)) ytitle("Standard deviations", size(large)) legend(off) title("Debt (% of GDP)", size(large)))
graph export "$project_path/output/appendix_figures/Appendix_Figure_E7a3.pdf", as(pdf) name("Graph") replace

** Appendix Figure E.7(a)4

rdrobust diff_m1_chix_govint runvar
local rdd_tau : di %8.3f e(tau_cl)
local rdd_lb : di %8.3f e(ci_l_rb)
local rdd_lb = subinstr("`rdd_lb'", " ", "", .)
local rdd_ub : di %8.3f e(ci_r_rb)
local rdd_ub = subinstr("`rdd_ub'", " ", "", .)
local rdd_pval : di %8.3f e(pv_rb)
if e(pv_rb)<0.001 local rdd_pval = "<0.001"
local N = e(N)
local rd_est = "RD est.: `rdd_tau' [`rdd_lb', `rdd_ub']. p-value: `rdd_pval'. N = `N'"

rdplot diff_m1_chix_govint runvar if inrange(runvar, -20, 20), p(1) nbins(10 10) graph_options(xtitle("Margin of victory of the challenger", size(large)) ylabel(-0.5(0.25)0.5, angle(0) labsize(large)) graphregion(color(white)) note("`rd_est'", tstyle(size(medlarge))) xlabel(-20(5)20, labsize(large)) ytitle("Standard deviations", size(large)) legend(off) title("Government intervention index", size(large)))
graph export "$project_path/output/appendix_figures/Appendix_Figure_E7a4.pdf", as(pdf) name("Graph") replace

** Appendix Figure E.7(b)1

rdrobust std_adiff_m1_exp_gdp runvar
local rdd_tau : di %8.3f e(tau_cl)
local rdd_lb : di %8.3f e(ci_l_rb)
local rdd_lb = subinstr("`rdd_lb'", " ", "", .)
local rdd_ub : di %8.3f e(ci_r_rb)
local rdd_ub = subinstr("`rdd_ub'", " ", "", .)
local rdd_pval : di %8.3f e(pv_rb)
if e(pv_rb)<0.001 local rdd_pval = "<0.001"
local N = e(N)
local rd_est = "RD est.: `rdd_tau' [`rdd_lb', `rdd_ub']. p-value: `rdd_pval'. N = `N'"

rdplot std_adiff_m1_exp_gdp runvar if inrange(runvar, -20, 20), p(1) nbins(10 10) graph_options(xtitle("Margin of victory of the challenger", size(large)) ylabel(-0.5(0.25)0.5, angle(0) labsize(large)) graphregion(color(white)) note("`rd_est'", tstyle(size(medlarge))) xlabel(-20(5)20, labsize(large)) ytitle("Standard deviations", size(large)) legend(off) title("Government expenditures (% of GDP)", size(large)))
graph export "$project_path/output/appendix_figures/Appendix_Figure_E7b1.pdf", as(pdf) name("Graph") replace

** Appendix Figure E.7(b)2

rdrobust std_adiff_m1_tax_revenue_wb runvar
local rdd_tau : di %8.3f e(tau_cl)
local rdd_lb : di %8.3f e(ci_l_rb)
local rdd_lb = subinstr("`rdd_lb'", " ", "", .)
local rdd_ub : di %8.3f e(ci_r_rb)
local rdd_ub = subinstr("`rdd_ub'", " ", "", .)
local rdd_pval : di %8.3f e(pv_rb)
if e(pv_rb)<0.001 local rdd_pval = "<0.001"
local N = e(N)
local rd_est = "RD est.: `rdd_tau' [`rdd_lb', `rdd_ub']. p-value: `rdd_pval'. N = `N'"

rdplot std_adiff_m1_tax_revenue_wb runvar if inrange(runvar, -20, 20), p(1) nbins(10 10) graph_options(xtitle("Margin of victory of the challenger", size(large)) ylabel(-0.5(0.25)0.5, angle(0) labsize(large)) graphregion(color(white)) note("`rd_est'", tstyle(size(medlarge))) xlabel(-20(5)20, labsize(large)) ytitle("Standard deviations", size(large)) legend(off) title("Tax revenue (% of GDP)", size(large)))
graph export "$project_path/output/appendix_figures/Appendix_Figure_E7b2.pdf", as(pdf) name("Graph") replace

** Appendix Figure E.7(b)3

rdrobust std_adiff_m1_debt_imf runvar
local rdd_tau : di %8.3f e(tau_cl)
local rdd_lb : di %8.3f e(ci_l_rb)
local rdd_lb = subinstr("`rdd_lb'", " ", "", .)
local rdd_ub : di %8.3f e(ci_r_rb)
local rdd_ub = subinstr("`rdd_ub'", " ", "", .)
local rdd_pval : di %8.3f e(pv_rb)
if e(pv_rb)<0.001 local rdd_pval = "<0.001"
local N = e(N)
local rd_est = "RD est.: `rdd_tau' [`rdd_lb', `rdd_ub']. p-value: `rdd_pval'. N = `N'"

rdplot std_adiff_m1_debt_imf runvar if inrange(runvar, -20, 20), p(1) nbins(10 10) graph_options(xtitle("Margin of victory of the challenger", size(large)) ylabel(-0.5(0.25)0.5, angle(0) labsize(large)) graphregion(color(white)) note("`rd_est'", tstyle(size(medlarge))) xlabel(-20(5)20, labsize(large)) ytitle("Standard deviations", size(large)) legend(off) title("Debt (% of GDP)", size(large)))
graph export "$project_path/output/appendix_figures/Appendix_Figure_E7b3.pdf", as(pdf) name("Graph") replace

** Appendix Figure E.7(b)4

rdrobust adiff_m1_chix_govint runvar
local rdd_tau : di %8.3f e(tau_cl)
local rdd_lb : di %8.3f e(ci_l_rb)
local rdd_lb = subinstr("`rdd_lb'", " ", "", .)
local rdd_ub : di %8.3f e(ci_r_rb)
local rdd_ub = subinstr("`rdd_ub'", " ", "", .)
local rdd_pval : di %8.3f e(pv_rb)
if e(pv_rb)<0.001 local rdd_pval = "<0.001"
local N = e(N)
local rd_est = "RD est.: `rdd_tau' [`rdd_lb', `rdd_ub']. p-value: `rdd_pval'. N = `N'"

rdplot adiff_m1_chix_govint runvar if inrange(runvar, -20, 20), p(1) nbins(10 10) graph_options(xtitle("Margin of victory of the challenger", size(large)) ylabel(-0.5(0.25)0.5, angle(0) labsize(large)) graphregion(color(white)) note("`rd_est'", tstyle(size(medlarge))) xlabel(-20(5)20, labsize(large)) ytitle("Standard deviations", size(large)) legend(off) title("Government intervention index", size(large)))
graph export "$project_path/output/appendix_figures/Appendix_Figure_E7b4.pdf", as(pdf) name("Graph") replace


